package br.com.locasis.conversores;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import br.com.locasis.utilitarios.UtilString;

@org.jboss.seam.annotations.faces.Converter(id="conversorHora")
public class ConversorHora implements Converter {

	public Object getAsObject(FacesContext context, UIComponent component, String valorCampo){
		Object hora = null;
		if(valorCampo != null) {
			if(!UtilString.isStringVazia(valorCampo)){
				hora = Integer.parseInt(valorCampo);
			}
		}
		return hora;
	}

	public String getAsString(FacesContext context, UIComponent component, Object objCampo){
		String hora = null;
		if(objCampo != null) {
			if(!UtilString.isStringVazia(objCampo.toString())){
				if(objCampo.toString().length()<2){
					hora = "0"+objCampo.toString();
				}else{
					hora = objCampo.toString();
				}
			}
		}
		return hora;
	}
	
}
